package com.login;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.model.StageInfo;
import com.test.R;
import com.test.StageListActivity;
import com.utils.Downloader;

public class LoginActivity extends Activity {

	private Downloader downloader;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		Button loginBtn = (Button) findViewById(R.id.loginBtn);
		loginBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				EditText usernameEditText = (EditText) findViewById(R.id.userName);
				EditText passwordEditText = (EditText) findViewById(R.id.password);
				String userName = usernameEditText.getText().toString();
				String password = passwordEditText.getText().toString();

				// this just catches the error if the program cant locate the
				// GUI stuff
				if (userName.equals("") || password.equals("")) {
					Toast message = Toast.makeText(LoginActivity.this,
							R.string.login_uncompleted, Toast.LENGTH_LONG);
					message.setGravity(Gravity.CENTER,
							message.getXOffset() / 2, message.getYOffset() / 2);
					message.show();
				} else
				{
					downloader=new Downloader();
					downloader.login("http://10.4.133.20/stage/index.php/site/login", userName, password,"test/","test");
					Intent intent = new Intent(LoginActivity.this,StageListActivity.class);
					startActivity(intent);
				}

			}

		}

		);

	}
}
